package com.jinyu.common.base;

import com.jinyu.common.enums.ApiRestCodeEnum;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author: yangli
 * @Despriction:
 * @Package: com.jinyu.common.base
 * @Date:Created in 2022/5/1 21:33
 * @Modify By:
 */
@Slf4j
public class ApiRestResponse<T> {

    private static final long serialVersionUID = -7616216747521482608L;

    /**
     * 状态码 - 来自枚举类 ApiRestCodeEnum
     * 2000为响应成功的状态,
     * 2100为响应为空的状态
     * 3000为错误状态
     */
    private int code;

    /**
     * 响应消息
     */
    private String msg;

    /**
     * 响应数据
     */
    private T data;

    public ApiRestResponse() {
    }

    public ApiRestResponse(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ApiRestResponse(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ApiRestResponse<T> ok() {
        return new ApiRestResponse<>(ApiRestCodeEnum.SUCCESS.getCode(), "操作成功");
    }

    public static <T> ApiRestResponse<T> ok(String msg) {
        return new ApiRestResponse<>(ApiRestCodeEnum.SUCCESS.getCode(), msg);
    }

    public static <T> ApiRestResponse<T> ok(int code, String msg) {
        return new ApiRestResponse<>(code, msg);
    }

    public static <T> ApiRestResponse<T> ok(String msg,T t) {
        return new ApiRestResponse<>(ApiRestCodeEnum.SUCCESS.getCode(), msg,t);
    }

    public static <T> ApiRestResponse<T> ok(T t) {
        return new ApiRestResponse<>(ApiRestCodeEnum.SUCCESS.getCode(), "操作成功！",t);
    }

    public static <T> ApiRestResponse<T> ok(int code, String msg, T t) {
        return new ApiRestResponse<>(code, msg,t);
    }

    public static <T> ApiRestResponse<T> err() {
        return new ApiRestResponse<>(ApiRestCodeEnum.FAIL.getCode(), "操作失败");
    }

    public static <T> ApiRestResponse<T> err(String msg) {
        return new ApiRestResponse<>(ApiRestCodeEnum.FAIL.getCode(), msg);
    }
    public static <T> ApiRestResponse<T> err(String msg,T t) {
        return new ApiRestResponse<>(ApiRestCodeEnum.FAIL.getCode(), msg,t);
    }

    public static <T> ApiRestResponse<T> err(int code,String msg) {
        return new ApiRestResponse<>(code, msg);
    }
    public static <T> ApiRestResponse<T> err(int code,String msg,T t) {
        return new ApiRestResponse<>(code, msg,t);
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
